//---------------------------------------------------------------------------


#pragma hdrstop

#include "BFISymbolsFactory.h"
#include "Unit1.h"

//---------------------------------------------------------------------------

#pragma package(smart_init)
map<String,BFISymbol*> BFISymbolsFactory::mCharacters;
map<String,String> BFISymbolsFactory::keys;

BFISymbolsFactory::BFISymbolsFactory()
		{
//			keys["and"] = "BFIAND";
//			keys["conv_implication"] = "BFIConvImplacation";
//			keys["empty_set"] = "BFIEmptySet";
//			keys["implication"] = "BFIImplication";
//			keys["or"] = "BFIOR";
//			keys["pirs"] = "BFIPirs";
//			keys["text_symbol"] = "BFITextSymbol";
//			keys["xor"] = "BFIXOR";
			keys = BFIExpression::getKeys();
		}

BFISymbol* BFISymbolsFactory::getSymbol(String key, TCanvas* Canvas,bool isInversed/*, int font_size*/)
		{
			if (keys.empty()) {
				new BFISymbolsFactory();
			}
			if (keys.count(key)) {
				Characters::const_iterator it = mCharacters.find(key);
				if (mCharacters.end() == it) {
					BFIConcreteCharacter* character =
						new BFIConcreteCharacter();
					BFISymbol* symbol = character->getSymbol(keys[key],Canvas/*,font_size*/);
					symbol->setInversed(isInversed);
					mCharacters[key] = symbol;
					return symbol;
				}
				else
					{
						it->second->setInversed(isInversed);
						it->second->setCanvas(Canvas);
						return it->second;
                    }
				}
			return NULL;
		}
